<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>注册</title>
	{css href="_css_/regist.css"} 
	{css href="_js_/layui/css/layui.css"}
	{js href="_js_/jquery2.1.4.min.js"}
	{js href="_js_/layer/layer.js"}
	{js href="_js_/layui/layui.js"}
	{js href="_js_/jquery.validate.min.js"}
	{js href="_js_/additional-methods.js"}
	{js href="_js_/jquery.form.js"}
</head>
<body>
	<form class="layui-form" method="post" action="javascript:;">
		<div class="layui-input-item title">
			<label>用户注册</label>
			<span>已有爱租网账号？</span>
			<a class="login" href="javascript:;">点此登录</a>
		</div>
		<div class="layui-input-item" style="height: 40px">
			<input class="layui-input" type="text" name="nickname" placeholder="用户名" required rangelength=[2,12] remote="{:url('index/login/check4')}">
		</div>
		<div class="layui-input-item" style="height: 40px">
			<input class="layui-input" type="text" name="tel" placeholder="手机号" required remote="{:url('index/login/check')}">
		</div>
		<div class="layui-input-item" style="height: 40px">
			<input class="layui-input" type="password" name="pwd" placeholder="登录密码" required rangelength=[6,16]>
		</div>
		<div class="layui-input-item" style="height: 40px">
			<input class="layui-input" type="password" name="pwd_confirm" placeholder="再次确认密码"  required rangelength=[6,16] equalto="input[name=pwd]">
		</div>
		<div class="layui-input-item" style="height: 40px">
			<div style="width:49%" class="layui-input-inline">
				<select name="city">
					<option value="">请选择城市</option>
					<option value="1">常州</option>
				</select>
			</div>
			<div style="width:49%" class="layui-input-inline">
				<select name="area">
					<option value="">请选择区/县</option>
					{volist name="data_area" id="vo"}
					<option value="{$vo.id}">{$vo.name}</option>
					{/volist}
				</select>
			</div>
		</div>
		<div class="layui-input-item" style="height: 40px">
			<div style="width:49%" class="layui-input-inline">
				<input class="layui-input" type="text" name="code" placeholder="输入验证码">
			</div>
			<div style="width:49%" class="layui-input-inline">
				<img id="code" style="height:45px" src="{:captcha_src()}" alt="">
			</div>
		</div>
		<div style="height: 40px">
			<button class="layui-btn" type="submit" id="submit">快&nbsp;速&nbsp;注&nbsp;册</button>
		</div>
	</form>

<script type="text/javascript">

	$('#code').click(function(){
		$(this).attr('src','{:captcha_src()}')
	});

	$().ready(function(){
		$('form').validate({
			rules:{
				tel:{
					isPhone:true,
				}
			},
			messages:{
				nickname:{
					required:'用户名不能为空',
					rangelength:'用户名为2-16位任意字符组合',
					remote:'用户名已存在',
				},
				tel:{
					required:'手机号不能为空',
					remote:'手机号已被注册',
				},
				pwd:{
					required:'密码不能为空',
					rangelength:'密码为6-16位任意字符组合',
				},
				pwd_confirm:{
					required:'密码不能为空',
					rangelength:'密码为6-16位任意字符组合',
					equalTo:'密码输入不一致',
				},
				city:{
					required:'请选择城市',
				},
			},
			submitHandler:function(form){
				$(form).ajaxSubmit({
					type:'post',
					url:'{:url('index/login/do_regist')}',
					datatype:'text',
					success:function(res){
						console.log(res.msg);
						if(res.msg != 1){
							layer.msg(res.msg,{icon:3,time:1000})
						}else{
							layer.msg('注册成功，请登录！',{icon:1,time:1000},function(){
								var index = parent.layer.getFrameIndex(window.name);
								parent.layer.close(index);
							})
						}
					}
				})
			}
		})
	})

	$('.login').click(function(){
		var index = parent.layer.getFrameIndex(window.name);
		parent.layer.close(index);	
	});

	layui.use('form',function(){
		var form = layui.form;
		form.render();
	});
</script>
</body>
</html>